var app = getApp()
Page({
  data: {
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 1200,
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    pageIndex: 1,
    arraydetail: [],
    author: 'Lotus'
  },
  getlist: function () {
    var that = this;
    that.setData({
      loadding: false
    });
    var arraydetail = that.data.arraydetail;
    var service = 'ProductPin.getMyPinsList';
    var pinStatus = that.data.currentTab;
    var pageIndex = that.data.pageIndex;
    var pageSize = 5;

    /*
   console.log("service:" + service);
   console.log("openId:" + app.globalData.openId);
   console.log("pinStatus:" + pinStatus);
   console.log("pageIndex:" + pageIndex);
   console.log("pageSize:" + pageSize);
    */

    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, pinStatus: pinStatus, pageIndex: pageIndex, pageSize: pageSize },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {

        //console.log("success:" + res.data.data);
        if (!res.data.data.code) {
          var dataresult = res.data.data.list.list;
          for (var i in dataresult) {
            arraydetail.push(dataresult[i]);
          }
          pageIndex++;
          that.setData({
            arraydetail: arraydetail,
            pageIndex: pageIndex,
            loadding: true
          })
        }

      },
    })
  },
  scroll: function (event) {
    //   该方法绑定了页面滚动时的事件，我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。
    this.setData({
      scrollTop: event.detail.scrollTop
    });
  },
  getmoredata: function () {
    //   该方法绑定了页面滑动到底部的事件
    this.getlist();
  },
  /** 
  * 滑动切换tab 
  */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },

  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {

      that.setData({
        pageIndex: 1,
        arraydetail: [],
        currentTab: e.target.dataset.current
      })

      that.getlist();
    }
  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode=options.fromInviteCode;
    }
    app.appstart();

    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
        that.getlist(0);
  }
})
